﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Common;
using DBA.Model;
using DBA.Data;
using DBA.Data.ADO;

namespace DBA.Web.SystemManage.BaseCodeManage
{
    public partial class SuoAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request.Params["id"]))
                {
                    hidID.Value = RequestHelper.QueryString("id");
                    ModifyRoleInit();
                }
            }
        }

        DataAccessLibrary dal = CommonQuery.DataAccessLibrary;

        protected void lnkSave_Click(object sender, EventArgs e)
        {

            Suo suoModel = new Suo();

            if (!VerificationHelper.IsNullOrEmpty<string>(hidID.Value))
            {
                suoModel.Suo_ID = ConvertHelper.ToInt32(hidID.Value);
            }
            suoModel.Name = txtName.Value.Trim();
            suoModel.Demo = txtDemo.Value.Trim();

            if (hidID.Value.Equals(string.Empty))//添加角色
            {
                hdResult.Value = dal.ModifyData.Insert<Suo>(suoModel).ToString();
            }
            else //修改角色
            {
                if (dal.ModifyData.Update<Suo>(suoModel) == "0")
                {
                    hdResult.Value = "0";
                }
                else
                {
                    hdResult.Value = "1";
                }
            }
        }

        /// <summary>
        /// 修改用户页面初始化
        /// </summary>
        private void ModifyRoleInit()
        {
            string id = hidID.Value;
            if (!VerificationHelper.IsNullOrEmpty<string>(hidID.Value))
            {
                Suo modelDpt = dal.ModifyData.GetEntity<Suo>(id);
                txtName.Value = modelDpt.Name;
                txtDemo.Value = modelDpt.Demo;
            }
        }
    }
}